<template>
  <div>
    <searchData :searchData="searchArr" @search="search"></searchData>
    <a-card>
      <!-- <title-name title="行为安全之星" /> -->
      <list-table
        ref="table"
        :columns="columns"
        :request="loadData"
        :exportConfig="{ use: true,select: '行为安全之星',all: '行为安全之星'}"
        :statisticsConfig="{use: true,statistics,temp}"
        :is-show-total="false"
      >
        <template slot="operation" slot-scope="text, record">
          <a @click="$nav('/safetySupervision/cardNotice/createCardLog/add',{id:record.id})">查看</a>
        </template>
      </list-table>
    </a-card>
  </div>
</template>

<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 项目
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { getList, getTotal } from '@/api/safetySupervision/safetyStar/safetyStarHonour.js'
import Moment from 'moment'
import Api from '@/api/safetySupervision/safetyStar/createCardLog'

export default {
  name: 'createCardLog',
  data() {
    return {
      searchArr: [
        {
          name: '所属单位',
          valueKey: 'searchQuery',
          type: OrgTreeSelect,
        },
        // {
        //   name: '所属分公司',
        //   valueKey: 'branchComId',
        //   type: SelectSubCompany
        // },
        // {
        //   name: '所属项目',
        //   keyValue: 'branchComId',
        //   valueKey: 'projectId',
        //   type: SelectProject
        // },
        {
          name: '分包单位',
          value: 'subcontractorName',
          type: 'input'
        },
        {
          name: '获奖人名字',
          value: 'employeeName',
          type: 'input'
        },
        {
          name: '获奖时间',
          value: 'monthDate',
          type: 'monthRange',
          setInitValue: true,
          initValue: [new Moment(), new Moment()],
          attr: {
            placeholder: ['请选择月份', '请选择月份']
          }
        }
      ],
      columns: [
        {
          title: '排名', dataIndex: 'index', width: 70, customRender() {
            return Number(arguments[2]) + 1
          }
        },
        { title: '姓名', dataIndex: 'employeeName', width: 120 },
        { title: '分包单位', dataIndex: 'subcontractorName' },
        { title: '班组', dataIndex: 'teamName', width: 140 },
        { title: '分公司', dataIndex: 'branchComName', width: 140 },
        { title: '所属项目', dataIndex: 'projectName', width: 210 },
        { title: '施工区域', dataIndex: 'respAreaName', width: 140 },
        { title: '表彰卡数量', dataIndex: 'cardSize', width: 140 },
        { title: '表彰卡面额', dataIndex: 'cardValue', width: 140 },
        {
          title: '操作',
          dataIndex: 'operation',
          width: 100,
          fixed: 'right',
          scopedSlots: { customRender: 'operation' }
        }
      ],
      statistics: 0,
      temp: () => {
        return (
          <span>
            发卡总数：{this.statistics || 0}个
          </span>
        )
      },
      queryParam: {}
    }
  },
  mounted() {
  },
  methods: {
    async loadData(parameter) {
      const params = Object.assign({}, parameter, { query: this.queryParam })
      if (params.query.monthDate && params.query.monthDate.length) {
        params.query.monthDateStart = Moment(params.query.monthDate[0]).startOf('month').format('YYYY-MM-DD HH:mm:SS')
        params.query.monthDateEnd = Moment(params.query.monthDate[1]).endOf('month').format('YYYY-MM-DD HH:mm:SS')
      } else if (params.query.monthDate && params.query.monthDate.length === 0) {
        params.query.monthDateStart = Moment('2020-01-01 00:00:00').startOf('month').format('YYYY-MM-DD HH:mm:SS')
        params.query.monthDateEnd = Moment(new Date()).endOf('month').format('YYYY-MM-DD HH:mm:SS')
      } else if(!params.query.monthDate) {
        params.query.monthDateStart = Moment(new Date()).startOf('month').format('YYYY-MM-DD HH:mm:SS')
        params.query.monthDateEnd = Moment(new Date()).endOf('month').format('YYYY-MM-DD HH:mm:SS')
      }
      params.query.type = 0
      Api.countTotal(params).then(res => {
        this.statistics = res.data || 0
      })
      return Api.findBusListByMain(params)
    },
    search(val = {}) {
      this.queryParam = val
      this.$refs.table.refresh()
    }
  }
}
</script>
